/* eslint valid-jsdoc: "off" */

'use strict'

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = (exports = {})

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1617114551698_122'

    // add your middleware config here
    // config.middleware = []

    // 跨域配置
    config.security = {
        csrf: {
            enable: false,
            ignoreJSON: true,
        },
        domainWhiteList: ['http://127.0.0.1'],
    }
    config.cors = {
        origin: 'http://127.0.0.1:8080', //一定要是域名端口
        credentials: true, //credentials设置为true,和前端保持一致
        allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
    }

    config.passportGithub = {
        key: 'shiquan_client',
        secret: 'shiquan_secret',
        // callbackURL: '/passport/github/callback',
        // proxy: false,
    }

    config.jwt = {
        secret: 'city-corner', // 自定义token 的加密条件字符串
    }

    config.redis = {
        client: {
            port: 6379, // Redis port
            host: '127.0.0.1', // Redis host
            password: '',
            db: 0,
        },
    }

    config.mongoose = {
        client: {
            url: 'mongodb://localhost:27017/city_corner',
            options: {
                useNewUrlParser: true,
            },
        },
        loadModel: false,
    }

    config.security = {
        csrf: {
            enable: false,
            ignoreJSON: true,
        },
        domainWhiteList: ['http://localhost:8080'], // 允许访问接口的白名单
    }

    config.cluster = {
        listen: {
            path: '',
            port: 8000,
            hostname: '127.0.0.1',
        },
    }

    // add your user config here
    const userConfig = {
        // myAppName: 'egg',
        sequelize: {
            dialect: 'mysql',
            host: 'localhost',
            port: '3306',
            user: 'shiquan',
            password: '1209yuyu',
            database: 'city_corner',
            timezone: '+08:00',
            define: {
                timestamps: false,
                freezeTableName: true,
            },
        },
    }

    return {
        ...config,
        ...userConfig,
    }
}

exports.swaggerdoc = {
    dirScanner: './app/controller', // 配置自动扫描的控制器路径
    // 接口文档的标题，描述或其它
    apiInfo: {
        title: 'Render', // 接口文档的标题
        description: 'swagger-ui for Render document.', // 接口文档描述
        version: '1.0.0', // 接口文档版本
    },
    schemes: ['http', 'https'], // 配置支持的协议
    consumes: ['application/json'], // 指定处理请求的提交内容类型（Content-Type），例如application/json, text/html
    produces: ['application/json'], // 指定返回的内容类型，仅当request请求头中的(Accept)类型中包含该指定类型才返回
    securityDefinitions: {
        // 配置接口安全授权方式
        // apikey: {
        //   type: 'apiKey',
        //   name: 'clientkey',
        //   in: 'header',
        // },
        // oauth2: {
        //   type: 'oauth2',
        //   tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
        //   flow: 'password',
        //   scopes: {
        //     'write:access_token': 'write access_token',
        //     'read:access_token': 'read access_token',
        //   },
        // },
    },
    enableSecurity: false, // 是否启用授权，默认 false（不启用）
    // enableValidate: true,    // 是否启用参数校验，默认 true（启用）
    routerMap: true, // 是否启用自动生成路由，默认 true (启用)
    enable: true, // 默认 true (启用)
}
